package org.langqiao.genericity;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class GenericTest {

	/**
	 * 泛型是编译器器时用的
	 * @param args
	 */
	public static void main(String[] args) {
		HashMap<String, Integer> maps = new HashMap<String, Integer>();
		maps.put("a", 1);
		maps.put("b", 2);
		maps.put("c", 3);
		
		Set<Map.Entry<String, Integer>> set = maps.entrySet();
		for (Map.Entry<String, Integer> entry : set) {
			System.out.println(entry.getKey()+"***********"+entry.getValue());
		}
		ArrayList<Integer> collection1 = new ArrayList<Integer>();
		try {
			collection1.getClass().getMethod("add", Object.class).invoke(collection1, "abc");
			collection1.getClass().getMethod("add", Object.class).invoke(collection1, 2);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		}
		System.out.println(collection1.get(0));
		System.out.println(collection1.get(1));
	}
}
